package com.aliyuncs.aui.service;

import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class DashscopeService {

    @Value("${biz.dashscope.api_key}")
    private String apiKey;

    @Value("${biz.dashscope.app_id}") 
    private String appId;

    public String callOrderModel(String prompt) throws ApiException, NoApiKeyException, InputRequiredException {
        System.out.println("callOrderConModel: " + prompt);
        
        ApplicationParam param = ApplicationParam.builder()
                .apiKey(apiKey)
                .appId(appId)
                .prompt(prompt)
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        return result.getOutput().getText();
    }
}
